package com.nut.course.api.biz;

import com.nut.course.common.Holder;
import com.nut.course.common.Result;
import com.nut.course.entity.TagUser;
import com.nut.course.interceptor.UserJwt;
import com.nut.course.service.TagUserService;
import com.nut.course.service.UserService;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.cp.bean.WxCpUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserService userService;

    @Autowired
    private TagUserService tagUserService;

    @GetMapping("/info")
    public Result<WxCpUser> getUserInfo() {
        UserJwt userJwt = Holder.USER_JWT_THREAD_LOCAL.get();
        log.info("userId=" + userJwt.getUserId());
        return userService.getUserInfo(userJwt.getUserId());
    }

    @GetMapping("/tags")
    public Result<List<TagUser>> getTagsByUserId() {
        UserJwt userJwt = Holder.USER_JWT_THREAD_LOCAL.get();
        log.info("userId=" + userJwt.getUserId());
        return tagUserService.getTagsByUserId(userJwt.getUserId());
    }

    @GetMapping("/getUsersByDepartId")
    public Result<List<WxCpUser>> getUsersByDepartId(@RequestParam Long departId) {
        return userService.getUsersByDepartId(departId);
    }

}
